package de.fhhannover.inform.hnefatafl.gui;

import de.fhhannover.inform.hnefatafl.spiel.Fassade;
import de.fhhannover.inform.hnefatafl.vorgaben.Move;


public class GUIController {
	
	private static GUIController instance = null;
	
	private GameFrame   		gameFrame;
	private StartPanel  		startPanel;
	private GamePanel   		gamePanel;
	private ManualPanel 		manualPanel;
	private AttackerStrategy 	attackerStrategy;
	private DefenderStrategy	defenderStrategy;
	private Fassade 			fassade;
	private int 				attackerKI,
								defenderKI;
	
	private GUIController(){
		
		gameFrame   =    new GameFrame();
		startPanel  =   new StartPanel();
		gamePanel   =    new GamePanel();
		manualPanel =  new ManualPanel();
		attackerStrategy = new AttackerStrategy();
		defenderStrategy = new DefenderStrategy();
		attackerKI = -1;
		defenderKI = -1;
		fassade = Fassade.getInstance();
		fassade.gamingBoard.addObserver(gamePanel);
		fassade.gamingBoard.moveChecker.addObserver(gamePanel);
		
	}
	
	public static GUIController getInstance(){
		if (instance == null){
			instance = new GUIController();
		}
		return instance;
	}
	
	public void exitGame(){
		System.exit(0);
	}
	
	public void initGameGUI(){
		gameFrame.setVisible(true);
		gameFrame.add(startPanel);
		
	}
	
	public void showAttackerStrategy(){
		attackerStrategy.setVisible(true);
	}
	
	public void showDefenderStrategy(){
		defenderStrategy.setVisible(true);
	}
	
	public void switchStartToGame(){
		gameFrame.remove(startPanel);
		gameFrame.add(gamePanel);
		gameFrame.validate();
		gameFrame.repaint();
	}

	public void switchStartToManual() {
		gameFrame.remove(startPanel);
		gameFrame.add(manualPanel);
		gameFrame.validate();
		gameFrame.repaint();
	}

	public void switchManualToStart() {
		gameFrame.remove(manualPanel);
		gameFrame.add(startPanel);
		gameFrame.validate();
		gameFrame.repaint();
	}
	
	public void setAttackerKI(int rowTab){
		attackerKI = rowTab;
	}
	
	public void setDefenderKI(int rowTab){
		defenderKI = rowTab;
	}

	public void initialGame(String attackerName, String defenderName,
							boolean isAttackerHuman, boolean isDefenderHuman, int kiDenkzeit) {
		Fassade.getInstance().initialisiereSpiel(attackerName, defenderName, isAttackerHuman, isDefenderHuman, kiDenkzeit, attackerKI, defenderKI);
		
	}
	
	public void makeMove(Move move){
		Fassade.getInstance().makeMove(move);
	}
	
}